#ifndef _STORAGE_H_
#define _STORAGE_H_

#include <unistd.h>
#include <pthread.h>

/**************************** DataType Declarations *************************/
enum storage_dev_type
{
	DEV_TYPE_SD = 0,
	DEV_TYPE_HARD,
	DEV_TYPE_FILE,
	DEV_TYPE_NET
};
enum storage_dev_status
{
	DEV_STATUS_EXIST,
	DEV_STATUS_MOUNT,
	DEV_STATUS_UMOUNT,
	DEV_STATUS_NEXIST,
};

enum storage_dev_rwflag
{
	DEV_FLAG_RDONLY = 1,
	DEV_FLAG_RDWR,
};

/* Device Layer Data Structure */
typedef struct storage_dev_meta
{
	int type;
	int max_num; /* system max device number supported */
	char mpoint[64]; /* absolute root mount point */
	int (*exist)(char *dev); /* return true or false */
	int (*mount)(char *dev,char *mpoint,char *options);
	int (*umount)(char *mpoint,char *options);
	int (*format)(char *dev,char *options);/** dev is devfs absolute filename */
}st_rsc_dev_meta;
typedef struct storage_dev_info
{
	pthread_mutex_t lock;
	int id; /* the device id number */
	int total_vol; /* unit is MBytes */
	int free_vol; /* unit is MBytes */
	int status; /* see storage_dev_status */
	int rw_flag; /* RDONLY or RDWRITE when mounted */
	char dev_node[32]; /* device node name */
	char mpoint[64]; /* absolute specific mount point */
}st_rsc_dev_info;	

/** Content Layer Data Structure */
enum storage_content_type
{
	CONT_TYPE_FILE = 1,
	CONT_TYPE_DIR,
};
enum storage_content_data
{
	CONT_DATA_REC = 0,
	CONT_DATA_VIDEO,
	CONT_DATA_AUDIO,
	CONT_DATA_PICTURE,
	CONT_DATA_ALARM,
	CONT_DATA_ALL,
	CONT_DATA_MAX
};
typedef struct storage_content_unit
{
	int type ;
	char pname[32];/* parent dir name */
	char name[32]; /* dir name or file name */
	int size;/* file size */
	time_t mtime;
}st_rsc_content_unit;
typedef struct storage_content_meta
{
	/* return true if filter ok,or false if filter fail. */
	int (*dir_filter[CONT_DATA_MAX])(st_rsc_content_unit *dir);
	int (*file_filter[CONT_DATA_MAX])(st_rsc_content_unit *file);
}st_rsc_content_meta;


/**************************** Function Declarations *************************/
/// Device Operations
int rsc_dev_mount(int dev_id,char *options);
int rsc_dev_umount(int dev_id,char *options);
int rsc_dev_format(int dev_id,char *options);

int rsc_get_dev_info(int id, st_rsc_dev_info *dev_info);
int rsc_get_all_vol(int *total_vol,int *free_vol);
/**
 * @param[in] size need space size by Bytes unit
 * @param[out] mpoint the mount point to access the device 
 */
int rsc_get_avail_dev(int size, char *mpoint);

/// Content Operations
void *rsc_get_root_list(int dev_id, int data_type);
void *rsc_get_dir_list(const char *dir,int data_type);
void *rsc_get_file_list(const char *dir,int data_type);
int rsc_free_file_list(void *list);
int rsc_get_file_info(const char *file, int *file_size);

/// Storage Init and Exit APIs
int rsc_init_storage(st_rsc_dev_meta *dmeta,st_rsc_content_meta *cmeta);
void rsc_exit_storage(void);

#endif

